/*
 * @Author: 1453937336@qq.com 1453937336@qq.com
 * @Date: 2024-05-31 12:51:57
 * @LastEditors: 1453937336@qq.com 1453937336@qq.com
 * @LastEditTime: 2024-06-12 11:46:56
 * @FilePath: \itforce-hris\src\store\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createStore } from "vuex";
import mutations from "./mutation";
import actions from "./actions";
import getters from "./getters";
import commonBoxs from './modules/commonBox';
import loginStore from './modules/loginStore';
import menuSetting from "./modules/menuSetting";
import positionStore from "./modules/positionStore";
import user from "./modules/user";
// vuex-persistedstate 来做vuex数据持久化 防止刷新浏览器数据丢失
import createPersistedState from "vuex-persistedstate";

export default createStore({
  modules: {
    commonBoxs,
    loginStore,
    menuSetting,
    positionStore,
    user,
  },
  state: {
    /** 所有路由 */
    permissionList: [],
    /** 导航菜单 */
    sidebarMenu: [],
    /* 面包屑导航列表 */
    crumbList: [],
    /** 当前active导航菜单 */
    currentMenu: "home",
    currentPath: "/home",
    isSidebarNavCollapse: false,
    roles: loginStore.state.roles || [],
    menuFirstChoose: 'home'
  },
  mutations,
  actions,
  getters,
  // 数据持久化设置
  plugins: [
    createPersistedState({
      // 默认存储在localStorage 现改为sessionStorage
      storage: window.sessionStorage,
      // 本地存储数据的键名
      key: "MY_VUEX",
      reducer(val) {
        // // consolelog('需要持久化的数据:', val);
        return {
          menuFirstChoose: val.menuFirstChoose,
          /** 所有路由 */
          permissionList: val.permissionList,
          /** 导航菜单 */
          sidebarMenu: val.sidebarMenu,
          /* 面包屑导航列表 */
          crumbList: val.crumbList,
          /** 当前active导航菜单 */
          currentMenu: val.currentMenu,
          currentPath: val.currentPath,
          isSidebarNavCollapse: val.isSidebarNavCollapse,
          roles: val.roles
        };
      },
    }),
  ],
});
